/*
 * Cube.cpp
 *
 *  Created on: Aug 23, 2011
 *      Author: andreas
 */

#include "Cube.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

Cube::Cube()
{
  r_ = 0.5f;
  red_   = 1.0f; //((GLfloat)rand() / RAND_MAX);
  green_ = 1.0f; //((GLfloat)rand() / RAND_MAX);
  blue_  = 1.0f; //((GLfloat)rand() / RAND_MAX);
  xrot_ = 0.0f;
  yrot_ = 0.0f;
  zrot_ = 0.0f;
}

Cube::Cube(GLfloat x, GLfloat y, GLfloat z)
{
  Cube();
  x_ = x;
  y_ = y;
  z_ = z;
}

Cube::~Cube() {}

void Cube::setPos(GLfloat x, GLfloat y, GLfloat z)
{
  x_ = x;
  y_ = y;
  z_ = z;
}

void Cube::draw()
{

  /* Move Into The Screen 5 Units */
  glLoadIdentity( );
  glTranslatef( x_ - 4.5f, y_, -10.0f );

  glRotatef( xrot_, 1.0f, 0.0f, 0.0f);
  glRotatef( yrot_, 0.0f, 1.0f, 0.0f);
  glRotatef( zrot_, 0.0f, 0.0f, 1.0f);

  glColor3f(red_, green_, blue_);
  glBegin(GL_QUADS);

  /* Front Face */
  glVertex3f( 0.0f - r_, 0.0f - r_, 0.0f + r_ );
  glVertex3f( 0.0f - r_, 0.0f + r_, 0.0f + r_ );
  glVertex3f( 0.0f + r_, 0.0f + r_, 0.0f + r_ );
  glVertex3f( 0.0f + r_, 0.0f - r_, 0.0f + r_ );

  /* Back Face */
  glVertex3f( 0.0f - r_, 0.0f - r_, 0.0f - r_ );
  glVertex3f( 0.0f - r_, 0.0f + r_, 0.0f - r_ );
  glVertex3f( 0.0f + r_, 0.0f + r_, 0.0f - r_ );
  glVertex3f( 0.0f + r_, 0.0f - r_, 0.0f - r_ );

  /* Top Face */
  glVertex3f( 0.0f - r_, 0.0f + r_, 0.0f + r_ );
  glVertex3f( 0.0f - r_, 0.0f + r_, 0.0f - r_ );
  glVertex3f( 0.0f + r_, 0.0f + r_, 0.0f - r_ );
  glVertex3f( 0.0f + r_, 0.0f + r_, 0.0f + r_ );

  /* Bottom Face */
  glVertex3f( 0.0f - r_, 0.0f - r_, 0.0f + r_ );
  glVertex3f( 0.0f - r_, 0.0f - r_, 0.0f - r_ );
  glVertex3f( 0.0f + r_, 0.0f - r_, 0.0f - r_ );
  glVertex3f( 0.0f + r_, 0.0f - r_, 0.0f + r_ );

  /* Right face */
  glVertex3f( 0.0f + r_, 0.0f - r_, 0.0f + r_ );
  glVertex3f( 0.0f + r_, 0.0f + r_, 0.0f + r_ );
  glVertex3f( 0.0f + r_, 0.0f + r_, 0.0f - r_ );
  glVertex3f( 0.0f + r_, 0.0f - r_, 0.0f - r_ );

  /* Left Face */
  glVertex3f( 0.0f - r_, 0.0f - r_, 0.0f + r_ );
  glVertex3f( 0.0f - r_, 0.0f + r_, 0.0f + r_ );
  glVertex3f( 0.0f - r_, 0.0f + r_, 0.0f - r_ );
  glVertex3f( 0.0f - r_, 0.0f - r_, 0.0f - r_ );

  glEnd( );

  xrot_ += 0.02;
  yrot_ += 0.04;
  zrot_ += 0.03;
}

